<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

    <title>设置</title>
    <link href="../../css/common.css" rel="stylesheet"/>
    <link href="../../css/user/index.css" rel="stylesheet"/>
    <link href="../../css/mui.min.css" rel="stylesheet"/>


    <script src="../../js/mui.min.js"></script>
    <script src="../../js/vue.min.js"></script>
    <script src="../../js/fastclick.js"></script>
    <script src="../../js/api.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/mui-componets.js"></script>
</head>
<body>

<div id="app">
    <div :style="{backgroundImage: 'url(' + showCommonImg(user.icon) + ')', backgroundSize:'contain'}"
         class="bg bg-blur"></div>
    <div class="nav-bg-box"></div>
    <div class="message-box content">
        <div class="user-info-box">
            <div class="header-img" :style="{backgroundImage: 'url(' + showCommonImg(user.icon, user.sex) + ')'}">
                <!--<img :src='showCommonImg(user.icon)' alt="">-->
                <img @click="selectPhoto" class="img-change" src="../../img/common/btn_changepic@3x.png" alt="">
            </div>
            <div class="title-name"> {{user.name}}</div>
            <div class="title-desc"> 账号：{{user.phone}}</div>
            <div class="title-desc"> 所在单位：{{user.orgName}}</div>
        </div>

        <div class="user-row-box">
            <div v-if="user.isManager==1" @click="goNetPerson" class="net-work"><img
                    src="../../img/common/ic_staff@3x.png" alt="">网点人员
            </div>
            <div v-else @click="goContact" class="net-work"><img src="../../img/common/ic_address@3x.png" alt="">通讯录
            </div>
        </div>

        <div v-show="statisticsBtn" class="user-row-box">
            <div @click="goStatistics" class="net-work"><img src="../../img/statistics/ic_statistics@3x.png" alt="">数据统计
            </div>
        </div>

        <div class="card-box li user-top">

            <div class="xlb-li">
                <div class="left user-left ">性别</div>
                <div class="right user-rigt">{{PERSON_SEX_MAP[user.sex]}}</div>
            </div>
            <div class="xlb-li">
                <div class="left user-left ">区域</div>
                <div class="right user-rigt">{{user.areaName}}</div>
            </div>

            <div class="xlb-li">
                <div class="left user-left ">人员状态</div>
                <div class="right user-rigt">{{user.statusName}}</div>
            </div>

        </div>


    </div>
</div>

<script>
    var vm = new Vue({
        el: '#app',
        mounted: function () {
            var userInfo = setUserInfo();
            if (userInfo) {
                this.user = userInfo;
            }
        },
        data: {
            user: {
                name: '',
                phone: '',
                icon: '../../img/user/img_default_man@3x.png',
                isManager: ''
            },
            // 统计菜单控制按钮
            statisticsBtn:false
        },
        methods: {
            showCommonImg: function (img, sex) {
                if (img) {
                    if (img == 'http://47.92.89.147' || img == 'http://47.92.89.147null') {
                        return '../../img/user/img_default_man@3x.png'
                    }
                    return img;
                } else {
                    // 女
                    if (sex === '1') {
                        return '../../img/user/img_default_woman@3x.png'
                    }
                    // 男
                    return '../../img/user/img_default_man@3x.png'

                }
            },
            // 跳转新页面
            goPage: function () {
                redirect('pages/order/orderDetail.html');
            },
            goNetPerson: function () {
                redirect('pages/user/netperson/index.html');
            },
            goContact: function () {
                redirect('pages/user/contact/index.html');
            },
            goStatistics: function () {
                redirect('pages/user/statistics/index.html');
            },
            //查询用户信息
            getUserInfo: function () {
                Resource.get(USER_INFO_API, {}, function (res) {
                    // 女
                    if (res.sex === '1') {
                        res.icon =  '../../img/user/img_default_woman@3x.png'
                    }else{
                        // 男
                        res.icon = '../../img/user/img_default_man@3x.png'
                    }
                    vm.user = res;
                    setUserInfo(res)
                })
            },
            //更新用户信息
            updateUser: function (data) {
                Resource.post(USER_UPDATE_API, data, function (res) {
                    var uCenter = plus.webview.getWebviewById('pages/uCenter.html')
                    mui.fire(uCenter, 'changeTab', {});
                })
            },
            //上传照片
            selectPhoto: function () {
                var _self = this;
                // 弹出系统选择按钮框
                plus.nativeUI.actionSheet({
                    title: "请选择",
                    cancel: "取消",
                    buttons: [{title: "拍照"}, {title: "相册"}]
                }, function (e) {
                    var index = e.index;
                    switch (index) {
                        case 2://相册选择
                            plus.gallery.pick(function (path) {
                                createUpload(path, function (data) {
                                    _self.user.icon = getImgServer() + data.data;
                                    _self.updateUser({icon: data.data + ''});
                                });
                            }, function (error) {

                            }, {filter: "image"});
                            break;
                        case 1://拍照
                            const cmr = plus.camera.getCamera();
                            const res = cmr.supportedImageResolutions[0];
                            const fmt = cmr.supportedImageFormats[0];
                            cmr.captureImage(function (path) {
                                    createUpload(path, function (data) {
                                        _self.user.icon = getImgServer() + data.data;
                                        _self.updateUser({icon: data.data + ''});
                                    });
                                },
                                function (error) {
                                    //取消
                                },
                                {resolution: res, format: fmt}
                            );
                            break;
                        default:
                            return;
                    }
                });
            }
        }
    });
</script>
<script>
    mui("body").on('tap', '.list-item', function (e) {
        vm.goPage();
    })
    // 禁用回退
    mui.init({
        beforeback: function () {
            return false;
        }
    })
    document.addEventListener('changeTab', function () {
        vm.getUserInfo();
        var permision = getUserPermission();
        vm.statisticsBtn =permision? permision['statistics']:false;
    })
</script>

</body>
</html>
